﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web;

namespace AviagePortal.Layouts.AviagePortal
{
    /// <summary>
    ///  /_layouts/15/AviagePortal/SearchAll.ashx?searchText=av&language=English&deviceType=PC
    /// </summary>
    public partial class SearchAll : IHttpHandler
    {
        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            System.Web.Script.Serialization.JavaScriptSerializer jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
            context.Response.ContentType = "application/json";

            string searchText = context.Request.QueryString["searchText"];
            string language = context.Request.QueryString["language"];
            string deviceType = context.Request.QueryString["deviceType"];

            SearchResultSummary result = SearchOperation.Search(searchText, language, deviceType);
            context.Response.Write(jsonSerializer.Serialize(result));
        }
    }
}
